import { Component, OnInit, Input } from '@angular/core';
import { ReportService } from '../../../report.service';
import { DATE_ZH_CN } from '../../../../common/configuration';

@Component({
  selector: 'report-standard-cond',
  templateUrl: './report-standard-cond.component.html',
  styleUrls: ['./report-standard-cond.component.scss']
})
export class ReportStandardCondComponent implements OnInit {
  @Input()
  set id(reportId: number) {
    if (!reportId) return;
    this.reportService.loadConditionFields(reportId).subscribe(conds => {
      this.conds = conds;
    })
    this.reportService.loadReport(reportId).subscribe(report => this.report = report);
  }
  get id(): number { return this.id; }

  report: any = {};

  zh: any = DATE_ZH_CN;
  conds: any = [];
  constructor(private reportService: ReportService) { }

  ngOnInit() {
  }
  /** 全局搜索 */
  search(){
    let conds = [];
    this.conds.forEach(c => {
      if(c.value){
        if(!c.comparetor){
          c.comparetor = c.comparetors[0];
        }
        conds.push({
          'comparetor': c.comparetor.value, 
          'fieldName': c.fieldName, 
          'dataTypeId': c.dataTypeId, 
          'value': c.value, 
          'value1': (c.value1 || '')
        });
      }
      this.reportService.announceMission(conds);
    });
    
  }
  /** 查询条件重置 */
  reset(){
    this.conds.forEach(ele => {
      ele.value='';
      ele.comparetor = ele.comparetors[0];  
    });
  }
}
